package panel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.UIManager;

import model.SystemCache;


/**
 * The first of the two panels that appear on the main application frame. This panel houses the back, next, up buttons,
 * the address bar as well the quick search bar.
 * @author Shahriar Haque
 *
 */
public class NavPanel extends JPanel {


	private static final long serialVersionUID = 1L;
	
	public static AddressBar ab;


	public NavPanel(){
		super(new BorderLayout());

		JToolBar toolBar = new JToolBar("Navigation Bar");
		toolBar.setFloatable(false);

		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		setPreferredSize(new Dimension(d.width - 40,75));

		
		ab = new AddressBar(75);
		
		SystemCache.loadCache();
		SystemCache.populateAddressBar(ab);

		setupToolBar(toolBar);

		add(toolBar, BorderLayout.PAGE_START);
		

	}

	private void setupToolBar(JToolBar bar){
		
		
		bar.add(makeNavigationButton("prev.png"));
		bar.add(makeNavigationButton("next.png"));
		bar.addSeparator();
		bar.add(makeNavigationButton("up.png"));
		
		ab.setFont(new Font("Tahoma",0,24));
		ab.setPreferredSize(new Dimension(500,25));
		
		bar.add(ab);
	}

	protected JButton makeNavigationButton(String imageName) {

		String imgLocation = "/media/Lemon Grass/" + imageName;
		URL imageURL = NavPanel.class.getResource(imgLocation);


		ImageIcon imageRollover = new ImageIcon(imageURL);
		
		return Utilities.getRolloverButton(imageRollover);


	}



	protected static void createAndShowGUI() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

		} catch (Exception e){
			System.err.println("Error settting look and feel");
		}

		JFrame frame = new JFrame("Navigation Panel");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JPanel panel = new NavPanel();

		frame.setContentPane(panel);
		frame.pack();
		frame.setVisible(true);

	}


	public static void main(String[] args) {
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				createAndShowGUI();
			}
		});

	}
}